package com.atguigu.yygh.hosp.service.impl;

import com.atguigu.yygh.hosp.mapper.HospitalSetMapper;
import com.atguigu.yygh.hosp.service.HospitalSetService;
import com.atguigu.yygh.model.hosp.HospitalSet;
import com.atguigu.yygh.vo.hosp.HospitalSetQueryVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class HospitalSetServiceImpl extends ServiceImpl<HospitalSetMapper, HospitalSet> implements HospitalSetService {


    // 2.条件查询+分页
    @Override
    public Page<HospitalSet> findPage(Page<HospitalSet> page, HospitalSetQueryVo hospitalSetQuery) {
        // 创建条件
        LambdaQueryWrapper<HospitalSet> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.like(!StringUtils.isEmpty(hospitalSetQuery.getHosname()), HospitalSet::getHosname, hospitalSetQuery.getHosname());
        lambdaQueryWrapper.eq(!StringUtils.isEmpty(hospitalSetQuery.getHoscode()), HospitalSet::getHoscode, hospitalSetQuery.getHoscode());

        return page(page, lambdaQueryWrapper);
    }


    // 根据医院编号查询sign key
    @Override
    public String getSignKey(String hoscode) {
        LambdaQueryWrapper<HospitalSet> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(HospitalSet::getHoscode, hoscode);
        HospitalSet hospitalSet = getOne(lambdaQueryWrapper);

        return hospitalSet.getSignKey();
    }
}
